﻿using AiQiuQuan.Sport.Model.Enums;
using System.ComponentModel.DataAnnotations;

namespace AiQiuQuan.Sport.Model.Models
{
    /// <summary>
    /// 比赛报名
    /// </summary>
    public class GameJoinRequestDto : IValidatableObject
    {
        /// <summary>
        /// 比赛ID
        /// </summary>
        [Required]
        public Guid GameId { get; set; }

        /// <summary>
        /// 队伍名称
        /// </summary>
        public string? Name { get; set; }

        /// <summary>
        /// 头像
        /// </summary>
        public string? HeadUrl { get; set; }

        /// <summary>
        /// 金额
        /// </summary>
        public decimal Amount { get; set; }

        /// <summary>
        /// 队伍明细
        /// </summary>
        [Required]
        [MinLength(1)]
        public List<GameTeamDetailDto> TeamDetailList { get; set; }

        /// <summary>
        /// validate
        /// </summary>
        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            foreach (var item in TeamDetailList)
            {
                if (TeamDetailList.Count(m => m.VersusType == item.VersusType) >= 2)
                {
                    yield return new ValidationResult("比赛项目对阵类型重复");
                    yield break;
                }
            }
        }
    }

    /// <summary>
    /// 报名队伍明细
    /// </summary>
    public class GameTeamDetailDto
    {
        /// <summary>
        /// 比赛项目对阵类型
        /// </summary>
        [Required]
        [EnumDataType(typeof(GameVersusEnum))]
        public GameVersusEnum VersusType { get; set; }

        /// <summary>
        /// 用户1ID
        /// </summary>
        [Required]
        public Guid User1Id { get; set; }

        /// <summary>
        /// 用户2ID，单打时无效
        /// </summary>
        public Guid? User2Id { get; set; }
    }
}
